#
# @lc app=leetcode.cn id=1128 lang=python3
#
# [1128] 等价多米诺骨牌对的数量
# 两层遍历的结果就是O(n^2)
# 那就只能用空间换取时间，第一次就记录信息

# @lc code=start
class Solution:
    def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:
        count_dict = {}
        ans = 0
        for first, second in dominoes:
            key = first * 10 + second if first > second else second * 10 + first
            count_dict[key] = count_dict.get(key, 0) + 1
            ans += count_dict[key] - 1
        return ans


# @lc code=end

